import React from 'react'
import PropTypes from 'prop-types'
import { Switch, Route, Redirect, routerRedux } from 'dva/router'
import dynamic from 'dva/dynamic'
import App from 'routes/app'
import { LocaleProvider } from 'antd'
import enUS from 'antd/lib/locale-provider/en_US'
import moment from 'moment'
import 'moment/locale/en-nz'

moment.locale('en-nz')// 控制当前的时区

const { ConnectedRouter } = routerRedux

const Routers = function ({ history, app }) {
  const error = dynamic({
    app,
    component: () => import('./routes/error'),
  })
  const routes = [
    {
      path: '/dashboard',
      models: () => [import('./models/dashboard')],
      component: () => import('./routes/dashboard/'),
    }, {
      path: '/user',
      models: () => [import('./models/user')],
      component: () => import('./routes/user/'),
    }, {
      path: '/user/:id',
      models: () => [import('./models/user/detail')],
      component: () => import('./routes/user/detail/'),
    },
    {
      path: '/basicdata',
      models: () => [import('./models/basicData')],
      component: () => import('./routes/basicData/'),
    },
    {
      path: '/reportbase',
      models: () => [import('./models/reportBase')],
      component: () => import('./routes/reportBase/'),
    },
    {
      path: '/companychargetype',
      models: () => [import('./models/companyChargeType')],
      component: () => import('./routes/companyChargeType/'),
    },
    {
      path: '/customer',
      models: () => [import('./models/customer')],
      component: () => import('./routes/customer/'),
    },
    {
      path: '/phone/:id/:type',
      models: () => [import('./models/phone')],
      component: () => import('./routes/phone/'),
    },
    {
      path: '/address/:id/:type',
      models: () => [import('./models/address')],
      component: () => import('./routes/address/'),
    },
    {
      path: '/entitydirector/:id',
      models: () => [import('./models/entityDirector')],
      component: () => import('./routes/entityDirector/'),
    },
    {
      path: '/entityDirectorData/:parentsId/:entityId',
      models: () => [import('./models/entityDirectorData/detail')],
      component: () => import('./routes/entityDirector/detail'),
    },
    {
      path: '/ident/:id/:type',
      models: () => [import('./models/identification')],
      component: () => import('./routes/identification/'),
    },
    {
      path: '/signatory/:accoutid',
      models: () => [import('./models/signatory')],
      component: () => import('./routes/signatory/'),
    },
    {
      path: '/employerphone/:personid/:type',
      models: () => [import('./models/employerPhone')],
      component: () => import('./routes/employerPhone/'),
    },
    {
      path: '/employeraddress/:personid/:type',
      models: () => [import('./models/employerAddress')],
      component: () => import('./routes/employerAddress/'),
    },
    {
      path: '/customer/detail/:id',
      models: () => [import('./models/customer/detail')],
      component: () => import('./routes/customer/detail/'),
    },
    {
      path: '/entity/:personid',
      models: () => [import('./models/entity')],
      component: () => import('./routes/entity/'),
    },
    {
      path: '/entity/detail/:customerId/:id',
      models: () => [import('./models/entity/detail')],
      component: () => import('./routes/entity/detail/'),
    },
    {
      path: '/accout/:id',
      models: () => [import('./models/accout')],
      component: () => import('./routes/accout/'),
    },
    {
      path: '/accout/detail/:customerId/:id',
      models: () => [import('./models/accout/detail')],
      component: () => import('./routes/accoutDetail'),
    },

    {
      path: '/sysUser/detail',
      models: () => [import('./models/sysUser/detail')],
      component: () => import('./routes/sysUser/detail/'),
    },
    {
      path: '/transactionreceipt',
      models: () => [import('./models/transactionReceipt')],
      component: () => import('./routes/transactionReceipt/'),
    },
    {
      path: '/transactionreceipt/detail/:id/:type',
      models: () => [import('./models/transactionReceipt/detail')],
      component: () => import('./routes/transactionReceipt/detail/'),
    },
    {
      path: '/transactionreceipt/detail/new/:id',
      models: () => [import('./models/transactionReceipt/detail')],
      component: () => import('./routes/transactionReceipt/detail/'),
    },
    {
      path: '/transactionAdminReceipt',
      models: () => [import('./models/transactionReceipt')],
      component: () => import('./routes/transactionAdminReceipt/'),
    },

    {
      path: '/transactionreport',
      models: () => [import('./models/transactionReport')],
      component: () => import('./routes/transactionReport'),
    },
    {
      path: '/transactionreport/detail/:id',
      models: () => [import('./models/transactionReport/detail')],
      component: () => import('./routes/transactionReport/detail/'),
    },
    {
      path: '/menu',
      models: () => [import('./models/menu')],
      component: () => import('./routes/menu/'),
    },
    {
      path: '/notices',
      models: () => [import('./models/notices')],
      component: () => import('./routes/notices/'),
    },
    {
      path: '/userNotices',
      models: () => [import('./models/notices')],
      component: () => import('./routes/userNotices/'),
    },
    {
      path: '/admincompanyaccount',
      models: () => [import('./models/adminCompanyAccount')],
      component: () => import('./routes/adminCompanyAccount/'),
    },
    {
      path: '/adminCompanyAccount/detail/:id/:name',
      models: () => [import('./models/adminCompanyAccount/detail')],
      component: () => import('./routes/adminCompanyAccount/detail/'),
    },
    {
      path: '/customersurplus',
      models: () => [import('./models/customerSurplus')],
      component: () => import('./routes/customerSurplus/'),
    },
    {
      path: '/customersurplus/detail/:id',
      models: () => [import('./models/customerSurplus/detail')],
      component: () => import('./routes/customerSurplus/detail'),
    },
    {
      path: '/servicerate',
      models: () => [import('./models/serviceRate')],
      component: () => import('./routes/serviceRate/'),
    },
    {
      path: '/transactionstatistics',
      models: () => [import('./models/transactionStatistics')],
      component: () => import('./routes/transactionStatistics/'),
    },
    {
      path: '/companyaccountsstatistics',
      models: () => [import('./models/companyAccountsStatistics')],
      component: () => import('./routes/companyAccountsStatistics/'),
    },
    {
      path: '/roles',
      models: () => [import('./models/roles')],
      component: () => import('./routes/roles/'),
    },
    {
      path: '/sysUser',
      models: () => [import('./models/sysUser')],
      component: () => import('./routes/sysUser/'),
    },
    {
      path: '/permissions',
      models: () => [import('./models/permissions')],
      component: () => import('./routes/permissions/'),
    },
    {
      path: '/login',
      models: () => [import('./models/login')],
      component: () => import('./routes/login/'),
    }, {
      path: '/request',
      component: () => import('./routes/request/'),
    }, {
      path: '/UIElement/iconfont',
      component: () => import('./routes/UIElement/iconfont/'),
    }, {
      path: '/UIElement/search',
      component: () => import('./routes/UIElement/search/'),
    }, {
      path: '/UIElement/dropOption',
      component: () => import('./routes/UIElement/dropOption/'),
    }, {
      path: '/UIElement/layer',
      component: () => import('./routes/UIElement/layer/'),
    }, {
      path: '/UIElement/dataTable',
      component: () => import('./routes/UIElement/dataTable/'),
    }, {
      path: '/UIElement/editor',
      component: () => import('./routes/UIElement/editor/'),
    }, {
      path: '/chart/ECharts',
      component: () => import('./routes/chart/ECharts/'),
    }, {
      path: '/chart/highCharts',
      component: () => import('./routes/chart/highCharts/'),
    }, {
      path: '/chart/Recharts',
      component: () => import('./routes/chart/Recharts/'),
    }, {
      path: '/post',
      models: () => [import('./models/post')],
      component: () => import('./routes/post/'),
    },
    {
      path: '/exchangeset',
      models: () => [import('./models/exchangeset')],
      component: () => import('./routes/exchangeset/'),
    },
    {
      path: '/servicefee',
      models: () => [import('./models/servicefee')],
      component: () => import('./routes/servicefee/'),
    },
    {
      path: '/exchangerate',
      models: () => [import('./models/exchangerate')],
      component: () => import('./routes/exchangerate/'),
    },
    {
      path: '/reports',
      models: () => [import('./models/report')],
      component: () => import('./routes/report/'),
    },
    {
      path: '/report/:id',
      models: () => [import('./models/reportDetail')],
      component: () => import('./routes/report/detail'),
    },
    {
      path: '/changelog',
      models: () => [],
      component: () => import('./routes/changeLog/'),
    },
  ]

  return (
    <ConnectedRouter history={history}>
      <LocaleProvider locale={enUS}>
        <App>
          <Switch>
            <Route exact path="/" render={() => (<Redirect to="/dashboard" />)} />
            {
              routes.map(({ path, ...dynamics }, key) => (
                <Route key={key}
                  exact
                  path={path}
                  component={dynamic({
                    app,
                    ...dynamics,
                  })}
                />
              ))
            }
            <Route component={error} />
          </Switch>
        </App>
      </LocaleProvider>
    </ConnectedRouter>
  )
}

Routers.propTypes = {
  history: PropTypes.object,
  app: PropTypes.object,
}

export default Routers
